﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Threading;
using System.Globalization;

/// <summary>
/// BasePage for the common funtionality in all 
/// the web pages of the site.
/// </summary>
/// 
namespace sdamarketing.App_Code
{
    public class BasePageNMP : Page
    {
        /// <summary>
        /// Default constructor
        /// </summary>
        public BasePageNMP()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public const string LanguageDropDownName = "ctl00$cphHeader$Header1$ddlLanguage";

         public const string PostBackEventTarget = "__EVENTTARGET";



        protected override void InitializeCulture()
        {
            /*
            if (Request[PostBackEventTarget] != null)
            {
                string controlID = Request[PostBackEventTarget];

                if (controlID.Equals("languagesDD"))
                {
                    string selectedValue = Request.Form[Request[PostBackEventTarget]].ToString();

                    switch (selectedValue)
                    {
                        case "en": SetCulture("en-US", "en-US");
                            break;
                        case "mk": SetCulture("mk-MK", "mk-MK");
                            break;
                        default: break;
                    }
                }
            }
            */
            if (Session["MyUICulture"] != null)
            {
                // Thread.CurrentThread.CurrentUICulture = (CultureInfo)Session["MyUICulture"];
                // Thread.CurrentThread.CurrentCulture = (CultureInfo)Session["MyCulture"];
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(Session["MyUICulture"].ToString());
                Thread.CurrentThread.CurrentCulture = new CultureInfo(Session["MyCulture"].ToString());

            }
            base.InitializeCulture();

        }
        protected void SetCulture(string name, string locale)
        {
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(name);
            Thread.CurrentThread.CurrentCulture = new CultureInfo(locale);
            Session["MyUICulture"] = Thread.CurrentThread.CurrentUICulture;
            Session["MyCulture"] = Thread.CurrentThread.CurrentCulture;
        }
    }

}
